package org.hi.trip.model;

import java.util.Date;

import org.hi.trip.model.original.TripAbstract;


public class Trip extends TripAbstract{


	@Override
	public double getPartnerPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_PARTNER)) {
				price = price - tripPrice.getIndividual_commission();
				break;
			}
		}
		return price;
	}
	
	@Override
	public double getPartnerGroupPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_PARTNER)) {
				price = price - tripPrice.getGroup_commission();
				break;
			}
		}
		return price;
	}

	@Override
	public double getPartnerNetworkPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_PARTNER)) {
				price = price - tripPrice.getIndividual_commission();
				price = price - tripPrice.getNet_commission();
				break;
			}
		}
		return price;
	}
	
	@Override
	public double getPartnerNetworkGroupPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_PARTNER)) {
				price = price - tripPrice.getIndividual_commission();
				break;
			}
		}
		return price;
	}

	@Override
	public double getCustomerPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_CUSTOMER)) {
				price = price - tripPrice.getIndividual_commission();
				break;
			}
		}
		return price;
	}
	
	@Override
	public double getCustomerGroupPrice() {

		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_CUSTOMER)) {
				price = price - tripPrice.getGroup_commission();
				break;
			}
		}
		return price;
	}

	@Override
	public double getCustomerNetworkPrice() {
		
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_CUSTOMER)) {
				price = price - tripPrice.getIndividual_commission();
				price = price - tripPrice.getNet_commission();
				break;
			}
		}
		return price;
	}
	
	@Override
	public double getCustomerNetworkGroupPrice() {
		double price = getDiscountPrice();
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_CUSTOMER)) {
				price = price - tripPrice.getGroup_commission();
				price = price - tripPrice.getNet_commission();
				break;
			}
		}
		return price;
	}

	@Override
	public double getDiscountPrice() {
		
		if(discount == 1d) return price;
		
		Date today = new Date();
		if(today.compareTo(discount_startDate) >= 0 && today.compareTo(discount_endDate) <= 0)
			return price*discount;
		
		return price;
	}

	@Override
	public int getPartnerGroupNumber() {

		int groupNumber = 1;
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_PARTNER)) {
				groupNumber = tripPrice.getGroup_number();
			}
		}
		
		return groupNumber;
	}

	@Override
	public int getCustomerGroupNumber() {
		
		int groupNumber = 1;
		
		for (TripPrice tripPrice : getTripPrices()) {
			if(tripPrice.getTo_whom().equals(CommissionTo.COMMISSIONTO_CUSTOMER)) {
				groupNumber = tripPrice.getGroup_number();
			}
		}
		
		return groupNumber;		
	}

}